<?php
use App\Http\Controllers\Api\Comment\DcommentController;
use App\Http\Controllers\Api\Dynamic\DynamicsController;
use App\Http\Controllers\Api\Image\AvatarsController;
use App\Http\Controllers\Api\Image\FilesController;
use App\Http\Controllers\Api\Image\ImagesController;
use App\Http\Controllers\Api\Message\GatewayEventsController;
use App\Http\Controllers\Api\Message\MessageController;
use App\Http\Controllers\Api\User\AuthorizationsController;
use App\Http\Controllers\Api\User\UsersController;
use App\Http\Controllers\Api\User\VerificationCodesController;
use App\Http\Controllers\Api\Vlog\VlogsController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::prefix('v1')
    //命名空间
    ->namespace('Api')
    //别名
    ->name('api.v1.')
    //中间件
    ->middleware('change-locale')
    ->group(function() {
        Route::middleware('throttle:' . config('api.rate_limits.access'))->group(function () {
            Route::get('version', function () {
                return 'this is version v1';
            })->name('version');

            // 短信验证码
            //Route::post('verificationCodes', [VerificationCodesController::class, 'store']) ->name('verificationCodes.store');
            // 图片验证码
            //Route::post('captchas', [CaptchasController::class, 'store'])->name('captchas.store');
            // 用户注册
            //Route::put('users', [UsersController::class, 'store']) ->name('users.store');
            // 用户登录
            //Route::post('authorizations', [AuthorizationsController::class, 'store'])->name('authorizations.store');

            // 手机号登录短信验证码
            Route::post('loginCodes', [VerificationCodesController::class, 'sendLoginCodes']) ->name('api.loginCodes');

            // 手机号登录
            Route::post('loginByCode', [AuthorizationsController::class, 'loginByCode'])->name('api.loginByCode');

            //获取所有游记
            Route::get('dynamics', [DynamicsController::class, 'index']) ->name('api.dynamics.index');

            //查看游记详情
            Route::post('dynamics', [DynamicsController::class, 'show']) ->name('api.dynamics.show');

            //获取某个游记下所有评论
            Route::get('dcomments', [DcommentController::class, 'index']) ->name('api.comments.index');

            //搜索游记
            Route::post('dynamics/search', [DynamicsController::class, 'searchIndex']) ->name('api.dynamics.search');

            //获取所有短视频
            Route::get('vlogs', [VlogsController::class, 'index']) ->name('api.vlogs.index');

            //查看短视频详情
            Route::post('vlogs', [VlogsController::class, 'show']) ->name('api.vlogs.show');

            //搜索短视频
            Route::post('vlogs/search', [VlogsController::class, 'searchIndex']) ->name('api.vlogs.search');

            // 获取其他用户的信息
            Route::post('users', [UsersController::class, 'show']) ->name('users.show');
        });
        Route::middleware('throttle:' . config('api.rate_limits.sign'))
            ->middleware('token.refresh')
            ->group(function () {

                // 刷新token
                Route::put('authorizations/current', [AuthorizationsController::class, 'update'])->name('authorizations.update');

                // 删除token
                Route::delete('authorizations/current', [AuthorizationsController::class, 'destroy'])->name('authorizations.destroy');

                // 获取登录用户的信息
                Route::get('users', [UsersController::class, 'me']) ->name('api.users.me');

                // 更新登录用户的信息
                Route::patch('users', [UsersController::class, 'update']) ->name('api.users.update');

                // 上传图片
                Route::post('images', [ImagesController::class, 'store'])->name('api.images.store');

                // 上传头像
                Route::post('avatars', [AvatarsController::class, 'store'])->name('api.avatars.store');

                //我的游记
                Route::get('dynamics/mine', [DynamicsController::class, 'mine']) ->name('api.dynamics.mine');

                //更新游记
                Route::patch('dynamics', [DynamicsController::class, 'update']) ->name('api.dynamics.update');

                //删除游记
                Route::post('dynamics/delete', [DynamicsController::class, 'destroy']) ->name('api.dynamics.delete');

                //点赞游记
                Route::post('dynamics/thumb', [DynamicsController::class, 'thumb']) ->name('api.dynamics.thumb');

                //收藏游记
                Route::post('dynamics/collect', [DynamicsController::class, 'collect']) ->name('api.dynamics.collect');

                //发表评论
                Route::post('comments', [DcommentController::class, 'store']) ->name('api.comments.store');

                //发布游记
                Route::post('dynamics/publish', [DynamicsController::class, 'store']) ->name('api.dynamics.store');

                //聊天相关
                //初始化
                Route::post('messages/init', [GatewayEventsController::class, 'init']) ->name('api.messages.init');
                //发消息
                Route::post('messages/send', [GatewayEventsController::class, 'send']) ->name('api.messages.send');

                //切换状态
                Route::post('messages/status', [GatewayEventsController::class, 'status']) ->name('api.messages.status');
                //会话列表
                Route::post('messages/list', [MessageController::class, 'list']) ->name('api.messages.list');
                //消息记录
                Route::get('messages/record', [MessageController::class, 'record']) ->name('api.messages.record');
                //上传文件
                Route::post('files', [FilesController::class, 'store']) ->name('api.files.store');
                //已读会话
                Route::post('messages/read', [GatewayEventsController::class, 'read']) ->name('api.messages.read');
                //创建会话表
                Route::post('messages/window', [MessageController::class, 'createWindow']) ->name('api.messages.createWindow');
                //隐藏会话表
                Route::post('messages/hideWindow', [MessageController::class, 'hideWindow']) ->name('api.messages.hideWindow');
                //视频通话
                Route::post('messages/video', [GatewayEventsController::class, 'videoCall']) ->name('api.messages.videoCall');
                //重置占线状态
                //Route::post('messages/resetBusy', [GatewayEventsController::class, 'resetBusy']) ->name('api.messages.resetBusy');
                //视频通话回调
                Route::post('messages/videoCallback', [GatewayEventsController::class, 'videoCallback']) ->name('api.messages.videoCallback');
            });
    });
